import React, { Component } from 'react';
import { NavBar } from 'antd-mobile'
// import { withRouter } from 'react-router-dom'
import { good_favlist } from '../utils/api'
import {connect} from  'react-redux'
import {request_cancel_collect_action} from '../store/ActionCreator'

class Collect extends Component {
    // state = {
    //     collectlist: []
    // }
    handleBack() {
        this.props.history.push('/index/mine')
    }
    // componentDidMount() {
    //     var userinfo = localStorage.getItem('userinfo')
    //     good_favlist({ userid: userinfo.id }).then((res) => {
    //         this.setState({ collectlist: res.data.list })
    //     })
    // }
    render() {
        return (
            <div className='collect'>
                <NavBar onBack={() => { this.handleBack() }}>
                    我的收藏
                </NavBar>
                <div className='goods'>
                    {
                        this.props.collectlist.map((item, index) => {
                            return (
                                <div className='good' key={index}>
                                    <div className='img-box'>
                                        <img src={item.pic} alt="" />
                                    </div>
                                    <div className='text'>
                                        <div className='name'>{item.name}
                                        </div>
                                        <div className="price">
                                            <span>活动价￥{item.salesPrice.value}</span>
                                            <button onClick={()=>{this.props.request_cancel_collect(item)}}>取消收藏</button>
                                        </div>
                                    </div>
                                </div>
                            )
                        })
                    }

                </div>
            </div>
        );
    }
}

export default connect(
    (state)=>{
        return{
            'collectlist':state.collectlist
        }
    },
    (dispatch)=>{
        return{
            request_cancel_collect(params) {
                dispatch(request_cancel_collect_action(params))
            }
        }
    }
)(Collect)
// withRouter(Collect);